<template>
  <view> </view>
</template>

<script>
import { getWxUserInfoApi } from "@/http/api";
import { getQueryObject } from "@/utils/index";
export default {
  data() {
    return {};
  },
  methods: {
    // 微信环境判断
    is_weixn() {
      var ua = window.navigator.userAgent.toLowerCase();
      if (ua.match(/MicroMessenger/i) == "micromessenger") {
        return true;
      } else {
        return false;
      }
    },
  },
  mounted() {},
  created() {
    uni.showLoading({
      title: "加载中",
    });
    let isWx = this.is_weixn();
    if (isWx === false) {
      uni.showToast({
        title: "请在微信客户端打开",
        icon: "none",
      });
      return;
    }
    let urlArr = window.location.href.split("#");
    let paramWx = getQueryObject(urlArr[0]);
    let code = paramWx.code;
    if (code) {
      getWxUserInfoApi({
        code: code,
        type: uni.getStorageSync("channel") || 0,
      }).then((res) => {
        if (res.code === 200) {
          uni.setStorageSync("wxInfo", res.data);
          if (res.data.state === 1) {
            // this.$store.commit("user/hasConcern");
          } else {
            this.$store.commit("user/cancelConcern");
          }
          uni.switchTab({
            url: "/pages/paipan/paipan",
          });
        } else {
          uni.showToast({
            title: "获取用户信息失败，请重新尝试扫码",
            icon: "none",
          });
        }
      });
    } else {
      uni.showToast({
        title: "用户code为空",
        icon: "none",
      });
    }
  },
};
</script>

<style></style>
